#include "gps.hpp"
#include "muduo/net/EventLoop.h"
#include "muduo/net/EventLoopThread.h"

namespace sensor::gps {
using namespace std::placeholders;
static muduo::net::EventLoopThread GpsReceiverThread;

GpsComponent::GpsComponent(const rclcpp::NodeOptions& options)
    : rclcpp::Node("gps", options)
{
    auto logger = rclcpp::get_logger("sensor::gps");
    RCLCPP_INFO(logger, "sersor::gps start !");
    auto loop = GpsReceiverThread.startLoop();
    gps_module_ = std::make_shared<GPSModule>("/dev/ttyUSB0", loop);
    gps_module_->setCallback(std::bind(&GpsComponent::GpsData, this, _1));
    gpsPubPtr_ = this->create_publisher<interface::msg::Gnss>("/sensor/gps/data", 30);
}

void GpsComponent::GpsData(const interface::msg::Gnss Gnss)
{
    gpsPubPtr_->publish(Gnss);
}

}